package com.fengpanlong.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.fengpanlong.entity.ContactNote;
import com.fengpanlong.util.DBHelp;
import com.fengpanlong.util.RowMapper;
import com.fengpanlong.util.StringUtil;

public class ContactNoteDao {
	private DBHelp<ContactNote> db = new DBHelp<ContactNote>();
	
	private class ContactNoteRowMapper implements RowMapper<ContactNote> {

		public ContactNote mapperRow(ResultSet rs) throws SQLException {
			ContactNote c = new ContactNote();
			c.setId(rs.getString("id"));
			c.setContent(rs.getString("content"));
			c.setCreatetime(StringUtil.formateTime(rs.getString("createtime")));
			c.setEmployeeId(rs.getString("employeeId"));
			return c;
		}
	}
	/**
	 * 通过联系人id和用户id查找记录列表
	 * @param contactId  联系人id
	 * @param employeeId 用户id
	 * @return 记录列表
	 */
	public List<ContactNote> findContactNotesByContactIdAndEmployeeId(
			String contactId, String employeeId) {
		String sql = "select id,content,createtime,employeeid from t_contactNote where contactid = ? and employeeid = ? order by createtime desc";
		return db.executeQueryForList(sql, new ContactNoteRowMapper(), contactId, employeeId);
	}
	/**
	 * 保存联系人记录
	 * @param contactNote 记录对象
	 * @param contactId 联系人id
	 * @param projectId 成员id
	 */
	public void saveContactNote(ContactNote c, String contactId,
			String employeeId) {
		String sql = "insert into t_contactnote(id,content,createtime,contactid,employeeid) values(?,?,?,?,?)";
		System.out.println(contactId);
		db.executeSQL(sql, c.getId(),c.getContent(),c.getCreatetime(),contactId,employeeId);
	}
	/**
	 * 删除记录
	 * @param contactId
	 */
	public void delContactNote(String contactId) {
		String sql = "delete from t_contactnote where contactid = ?";
		db.executeSQL(sql, contactId);
	}
	
}
